package com.example.barcodeapp.ui.home;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.RecyclerView;

import com.bumptech.glide.Glide;
import com.example.barcodeapp.R;
import com.example.barcodeapp.common.Constants;
import com.example.barcodeapp.ui.home.activity.JiangshiActivity;
import com.example.barcodeapp.ui.home.activity.JiaoShiXiangQingJieMianActivity;
import com.example.barcodeapp.ui.home.activity.RiLiActivity;
import com.example.barcodeapp.ui.home.bean.JiaoShiNeiRongBean;
import com.example.barcodeapp.ui.own.activity.XiangQingActivity;
import com.example.barcodeapp.utils.Show;

import java.util.List;

public class JiaoshiAdapter extends RecyclerView.Adapter<JiaoshiAdapter.ViewHolder> {

    private Context context;


    public JiaoshiAdapter(Context context) {
        this.context = context;
    }
    public List<JiaoShiNeiRongBean.DataEntity> list;

    public JiaoshiAdapter(Context context, List<JiaoShiNeiRongBean.DataEntity> list) {
        this.context = context;
        this.list = list;
    }

    private IClick callback;

    public void setClick(IClick cb) {
        callback = cb;
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        View inflate = LayoutInflater.from(context).inflate(R.layout.adapter_jiaoshi, parent, false);
        return new ViewHolder(inflate);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        holder.yuele.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Show.showMessage("约课");
                context.startActivity(new Intent(context, RiLiActivity.class));

            }
        });
        holder.chakan.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Constants.jiasohilanmuid=list.get(position).getId();
                Intent instant = new Intent(context, JiaoShiXiangQingJieMianActivity.class);
                instant.putExtra("neirong","状态");
                instant.putExtra("data",list.get(position).getId());
                context.startActivity(instant);

            }
        });

        if (position==4){
            holder.yueguo.setVisibility(View.INVISIBLE);
        }else {
            holder.yueguo.setVisibility(View.VISIBLE);
        }
        Glide.with(context).load(Constants.Base_TPUrl2 +list.get(position).getImage()).into(holder.imageView16);
        holder.textView44.setText(list.get(position).getName());
        holder.textView15.setText(list.get(position).getPrice());
        holder.textView45.setText(list.get(position).getDengji());
        holder.textView46.setVisibility(View.INVISIBLE);

    }

    @Override
    public int getItemCount() {
        return list.size();
    }



    public class ViewHolder extends RecyclerView.ViewHolder {
        private ImageView imageView16;
        private TextView textView44;
        private TextView textView45;
        private TextView textView46;
        private TextView yueguo;
        private TextView textView15;
        private TextView textView48;
        private ImageView imageView4;
        private TextView textView14;
        private TextView yuele;
        private TextView chakan;

        public ViewHolder(@NonNull View itemView) {
            super(itemView);
            imageView16 = (ImageView) itemView.findViewById(R.id.imageView16);
            textView44 = (TextView) itemView.findViewById(R.id.textView44);
            textView45 = (TextView) itemView.findViewById(R.id.textView45);
            textView46 = (TextView) itemView.findViewById(R.id.textView46);
            yueguo = (TextView) itemView.findViewById(R.id.yueguo);
            textView15 = (TextView) itemView.findViewById(R.id.textView15);
            textView48 = (TextView) itemView.findViewById(R.id.textView48);
            imageView4 = (ImageView) itemView.findViewById(R.id.imageView4);
            textView14 = (TextView) itemView.findViewById(R.id.textView14);
            yuele = (TextView) itemView.findViewById(R.id.yueke);
            chakan = (TextView) itemView.findViewById(R.id.chakan);
        }
    }

    public interface IClick {

        void click(int pos);

    }
}
